package com.micro.modual.extension;

import com.micro.common.MicroConstant;
import com.micro.common.biz.GeneratorCodeUtil;
import com.micro.common.util.SnowFlakeUtil;
import com.micro.modual.entity.GoodsSku;
import com.micro.modual.entity.SeckillDetail;
import com.micro.modual.model.bo.seckilldetail.SeckillDetailBO;
import com.micro.modual.model.dto.goodssku.GoodsSkuListDTO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <h1>秒杀商品详情表 延展类</h1>
 *
 * @author LevelCoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020-08-04 00:23:26
 */
public class SeckillDetailExtension {

    public static List<SeckillDetail> convertAddSeckillDetail(SeckillDetailBO seckillDetailBO) {
        List<SeckillDetail> seckillDetailList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(seckillDetailBO.getSeckillGoodsList())){
            for(SeckillDetailBO.Goods goods:seckillDetailBO.getSeckillGoodsList()){
                SeckillDetail seckillDetail = new SeckillDetail();
                seckillDetail.setId(SnowFlakeUtil.getId());
                seckillDetail.setCreateTime(new Date());
                seckillDetail.setGoodsCode(goods.getGoodsCode());
                seckillDetail.setGoodsImage(goods.getGoodsImage());
                seckillDetail.setGoodsName(goods.getGoodsName());
                seckillDetail.setSeckillCode(seckillDetailBO.getSeckillCode());
                seckillDetail.setSeckillGoodsCount(goods.getSeckillGoodsCount());
                seckillDetail.setSeckillGoodsOriginalPrice(goods.getSeckillGoodsOriginalPrice());
                seckillDetail.setSeckillGoodsPrice(goods.getSeckillGoodsPrice());
                seckillDetail.setSeckillGoodsQuota(goods.getSeckillGoodsQuota());
                seckillDetail.setSeckillGoodsSort(goods.getSeckillGoodsSort());
                seckillDetail.setSeckillSceneCode(seckillDetailBO.getSeckillSceneCode());
                seckillDetail.setSeckillStockCount(goods.getSeckillStockCount());
                seckillDetail.setSeckillGoodsRateType(goods.getSeckillGoodsRateType());
                if(goods.getSeckillGoodsRateType() == (byte) 2){
                    seckillDetail.setSeckillGoodsRate(goods.getSeckillGoodsRate());
                }
                seckillDetailList.add(seckillDetail);
            }
        }
        return seckillDetailList;
    }



    public static List<GoodsSkuListDTO> convertGoodsSkuListDTO(List<String> skuCodeList, List<GoodsSku> goodsSkuList) {
        List<GoodsSkuListDTO> goodsSkuListDTOList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(goodsSkuList)){
            for(GoodsSku goodsSku:goodsSkuList){
                if(skuCodeList.contains(goodsSku.getSkuCode())){
                    continue;
                }
                GoodsSkuListDTO goodsSkuListDTO = new GoodsSkuListDTO();
                BeanUtils.copyProperties(goodsSku,goodsSkuListDTO);
                goodsSkuListDTOList.add(goodsSkuListDTO);
            }
        }
        return goodsSkuListDTOList;
    }
}
